home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-07-15 | 5.9 KB | 228 lines | [TEXT/?bDv] |
- !
- ! Middle
- !
- ! This bot uses a number of the more advanced design options,
- ! including intelligent damage recognition and a repair
- ! mechanism. It takes advantage of the fact that from the
- ! middle of the arena you are always scanning at a fairly close
- ! distance, so it's more likely that a given scan will find an
- ! enemy bot (Which means you want a very wide scan increment
- ! when scanning in a circle).
-
-
- #DATA
-
- EQU INCR 37
- EQU FIND_INCR 11
-
- DEF scn
- DEF d
- DEF damageLoc
- DEF temp
- DEF cpuThresh
- DEF firstTime 0
-
- #CODE BASIC
-
- cpuThresh = $CPU/2 ! If CPU < 1/2 MAXCPU, then the repair
- ! mechanism might jam. Therefore,
- ! don't use it to time movements.
-
- d = $DAMAGE
- Goto RunawayStart ! Move to center
-
- :Start
- d = $DAMAGE
- scn = Random(360)
-
- :ScanLoop
- If ($DAMAGE <> d) Then Goto GotHit
- scn = scn + INCR
- Scan Angle scn
- If ($FOUND == 0) Then Goto ScanLoop
- :ScanLock
- Fire Weapon 1, Angle $ANGLE
- If ($DAMAGE <> d) Then Goto GotHit
- Scan Angle $ANGLE ! Center the scanner on the enemy
- If ($FOUND <> 0) Then Goto ScanLock
- ! If we lost the lock, continue on
-
- :LockOn ! Try to locate the moving enemy
- Scan Angle scn-43
- If ($FOUND <> 0) Then Goto ScanLock
- Scan Angle scn-43 + FIND_INCR
- If ($FOUND <> 0) Then Goto ScanLock
-
- If ($DAMAGE <> d) Then Goto GotHit !In case we've been hit
-
- Scan Angle scn-43 + FIND_INCR*2
- If ($FOUND <> 0) Then Goto ScanLock
- Scan Angle scn-43 + FIND_INCR*3
- If ($FOUND <> 0) Then Goto ScanLock
-
- Goto ScanLoop ! Couldn't find him.
-
- ! These routines are called if damage is taken while we're
- ! sitting in the center of the arena. Calls to the REPAIR
- ! mechanism are used to time the movement (and they repair the
- ! CPU if it gets damaged). The bot will basically make a loop
- ! and go back into the middle.
-
- :GotHit
- Velocity 220, 70 ! Start running immediately
- damageLoc = $DAMAGEDIR
- If ($CPU >= cpuThresh) Then
- begin
- Repair C_CPU For 2 ! Repair the CPU for 20
- Velocity -70, -220
- Repair C_CPU For 2 ! Repair some more
- d = $DAMAGE
- end
- Else ! If CPU has been damaged:
- begin
- Wait 20 ! If the repair mechanism jams due
- ! to the damaged CPU, we might keep
- ! repairing as we moved right into
- ! a wall! Don't take that chance.
- Velocity -40, -150
- Repair C_CPU For 2
- Velocity 0, 0
- d = $DAMAGE
- end
-
- ! Move to the center of the arena. If you get hit, go to the
- ! appropriate DAMAGE routine, below. This is the same basic
- ! movement routine used by the previous bots, except that it
- ! checks for damage.
-
- :RunawayStart
- temp = Random(360) ! Pick a random firing angle
- Fire Weapon 1, Angle temp
- :RunawayX
- If (d <> $DAMAGE) Then Goto XDamage
- :ContinueX
- Velocity (128-$XLOC)*4, 0
- Fire Weapon 1 ! Fire while moving. Why not?
- ! After all, you might hit someone.
- If ($XLOC > 136) Then Goto RunawayX
- If ($XLOC < 120) Then Goto RunawayX
- Velocity 0, 0
-
- :RunawayY
- If (d <> $DAMAGE) Then Goto YDamage
- :ContinueY
- Velocity 0, (128-$YLOC)*4
- Fire Weapon 1
- If ($YLOC > 136) Then Goto RunawayY
- If ($YLOC < 120) Then Goto RunawayY
- Velocity 0, 0
-
- firstTime = firstTime + 1
- If (firstTime == 1) Then Goto Start
- ! Don't do the following routine
- ! the first time we move.
-
- ! Use the Damage Recognition System: The general direction of
- ! the shot that hit us is now stored in DAMAGE_LOC (it was in
- ! $DAMAGELOC), but DAMAGE_LOC got a copy of it right after we
- ! started to run away). That value is accurate (roughly)
- ! within 45 degrees. So, start scanning 45ish degrees less
- ! than that value and try to find your attacker.
-
- d = $DAMAGE
- For scn = (Random(4)+damageLoc-47) &
- To damageLoc + 43 &
- Step FIND_INCR
- :FindScanLock
- If (d <> $DAMAGE) Then Goto GotHit
- ! Jump out of For-Next!
- Scan Angle scn
- If ($FOUND <> 0) Then
- begin
- Fire Weapon 1, Angle $ANGLE
- Goto FindScanLock ! Still locked on
- end
- Next scn ! No lock.
-
- Goto Start
-
-
- ! These routines are called if the bot takes damage while
- ! moving to the center of the arena. They check to see if the
- ! damage was due to a collision ($DAMAGETYPE == 4). If not,
- ! then don't worry about it, as the enemy probably can't lock
- ! on to a moving target too well. If so, then we bumped into
- ! someone. Scan for them and shoot if we find them.
-
-
- :XDamage
- d = $DAMAGE
- If ($DAMAGETYPE <> C_COLLIDE) Then Goto ContinueX
- ! Damage was from a collision
- If ($XLOC > 130) Then ! Are we moving left or right?
- begin
- Velocity 10, 0 ! (Back up slowly while firing)
- scn = 180
- end
- Else
- begin
- Velocity -10, 0
- scn = 0
- end
- Scan Angle scn ! Scan along the x-axis
- If ($FOUND <> 0) Then Goto XQuickShot
- Scan Angle scn-30 ! Scan -30 degrees from the x-axis
- If ($FOUND <> 0) Then Goto XQuickShot
- Scan Angle scn+30 ! Scan +30 degrees from the x-axis
- If ($FOUND <> 0) Then Goto XQuickShot
- d = $DAMAGE
- Goto ContinueX
-
- :XFireAt
- Scan Angle $ANGLE ! Center the scanner on the enemy
- If ($FOUND == 0) Then
- begin
- d = $DAMAGE
- Goto ContinueX
- end
- :XQuickShot
- Fire Weapon 1, Angle $ANGLE
- Goto XFireAt
-
-
- :YDamage
- d = $DAMAGE
- If ($DAMAGETYPE <> C_COLLIDE) Then Goto ContinueY
- ! Damage was from a collision
- If ($YLOC > 130) Then ! Are we moving up or down?
- begin
- Velocity 0, 10 ! (Back up slowly while firing)
- scn = 270
- end
- Else
- begin
- Velocity 0, -10
- scn = 90
- end
- Scan Angle scn ! Scan along the y-axis
- If ($FOUND <> 0) Then Goto YQuickShot
- Scan Angle scn-30 ! Scan -30 degrees from the y-axis
- If ($FOUND <> 0) Then Goto YQuickShot
- Scan Angle scn+30 ! Scan +30 degrees from the y-axis
- If ($FOUND <> 0) Then Goto YQuickShot
- d = $DAMAGE
- Goto ContinueY
-
- :YFireAt
- Scan Angle $ANGLE ! Center the scanner on the enemy
- If ($FOUND <> 0) Then
- begin
- d = $DAMAGE
- Goto ContinueY
- end
- :YQuickShot
- Fire Weapon 1, Angle $ANGLE
- Goto YFireAt
-
- #END
-